

package com.zl.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

/**
 * @author zl
 * @date 2023/3/7
 * @apiNote
 */


// 开启swagger3
@EnableOpenApi
//配置swagger
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket docket() {
        // return new Docket(DocumentationType.OAS_30).apiInfo(new ApiInfoBuilder().title("测试swagger是否启动成功").build());
        // OAS_30 swagger3.0.0中有的新特性
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                // .enable(false)是否启用Swagger,如果为false，则swagger不能再用浏览器中访问
                // .enable(false)
                .select()
                // RequestHandlerSelectors,配置要扫描接口的方式
                // RequestHandlerSelectors.basePackage("com.zl.controller")制定扫描的包
                // RequestHandlerSelectors.any()扫描全部
                // RequestHandlerSelectors.none()都不扫描
                // RequestHandlerSelectors.withClassAnnotation(RestController.class)扫描类上的注解
                // RequestHandlerSelectors.withMethodAnnotation(RestController.class)扫描方法上的注解

                // .paths() 过滤什么路径(拦截)
                // .paths(PathSelectors.ant("/zl/**"))
                .apis(RequestHandlerSelectors.basePackage("com.zl.controller"))
                .build(); //工厂模式

    }

    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.OAS_30).groupName("A");
    }
    @Bean
    public Docket docket2() {
        return new Docket(DocumentationType.OAS_30).groupName("B");
    }
    @Bean
    public Docket docket3() {
        return new Docket(DocumentationType.OAS_30).groupName("C");
    }

    //配置swagger的信息 :  apiInfo
    private ApiInfo apiInfo() {
        //作者信息
        Contact contact = new Contact("zl", "ttp://www.baidu.com", "1272633570@qq.com");
        return new ApiInfo("zl的swaggeAPI文档",
                "心之所向，素履以往",
                "1.0",
                "http://www.baidu.com",
                contact,
                "Apache2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
